import {getIssuesList} from "@/api/issues.js";
import {getIssuePk, getIssueStatus, setCurrentPid, setIssuePk, setIssueStatus} from "@/utils/project_core.js";
import sys from "@/store/modules/sys.js";

const issue = {
    state: {
        searchParam: '',
        current:1,
        pageSize:10,
        totalCount:0,
        current_issue_pk : getIssuePk(),
        issue_status : getIssueStatus(),
        current_issues_data: null
    },
//更改state的mutation，只能进行同步
    mutations: {
        SET_SEARCH_PARAM:(state,param) => {
            state.searchParam = param
        },
        SET_CURRENT_PID: (state,pid)=>{
            state.current_pid = pid
            setCurrentPid(pid)
        },
        SET_CURRENT_ISSUE_PK: (state,issue_pk)=>{
            state.current_issue_pk = issue_pk
            setIssuePk(issue_pk)
        },
        SET_ISSUE_STATUS: (state,issue_status)=>{
            state.issue_status = issue_status
            setIssueStatus(issue_status)
        },
        SET_CURRENT_ISSUES_DATA:(state,issues_data)=>{
            state.current_issues_data = issues_data
        },
        SET_CURRENT_PAGE: (state,current)=>{
            state.current = current
        },
        SET_PAGE_SIZE:(state,pageSize)=>{
            state.pageSize = pageSize
        },
        SET_TOTAL_COUNT:(state,totalCount)=>{
            state.totalCount = totalCount
        },

    },

    //包含了mutations的action，可以使用异步
    actions: {
        issueStatusChange({commit},key){
            commit('SET_ISSUE_STATUS',key)
        },
        issueChange({commit},key){
            commit('SET_CURRENT_ISSUE_PK',key)
        },
        issuesDataCache({commit},key){
            commit('SET_CURRENT_ISSUES_DATA',key)
            return 1
        },
        setSearchParam({commit},param){
            commit('SET_SEARCH_PARAM',param)
        },
        storeSetCurrentPage({commit},current){
            commit('SET_CURRENT_PAGE',current)
        },
        storeSetPageSize({commit},pageSize){
            commit('SET_PAGE_SIZE',pageSize)
        },
        storeSetPageNumSize({commit},page){
            console.log('storeSetPageNumSize',page)
            commit('SET_CURRENT_PAGE',page.pageNum)
            commit('SET_PAGE_SIZE',page.pageSize)
        },
        storeSetTotalCount({commit},totalCount){
            commit('SET_TOTAL_COUNT',totalCount)
        },


    },

    getters: {
        searchParam: state => state.searchParam,
        current_issue_pk: state => state.current_issue_pk,
        issue_status: state=>state.issue_status,
        issues_data: state=>state.current_issues_data,
        current: state=>state.current,
        pageSize: state=>state.pageSize,
        totalCount: state=>state.totalCount,
        // current_issues_data : state=>state.current_issues_data
    }
}

export default issue
